﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;

namespace DCSoft.TemperatureChart
{
    /// <summary>
    /// 体温单测量数据
    /// </summary>
    /// <remarks>编制 袁永福</remarks>
    [ComVisible(false)]
    public class Measure
    {
        /// <summary>
        /// 初始化对象
        /// </summary>
        public Measure()
        {
        }

        private string _RecordID = null;
        /// <summary>
        /// 记录编号
        /// </summary>
        [DefaultValue(null)]
        public string RecordID
        {
            get { return _RecordID; }
            set { _RecordID = value; }
        }

        private DateTime _ValueDate = TemperatureDocument.NullDate;
        /// <summary>
        /// 测量日期
        /// </summary>
        [DefaultValue(typeof(DateTime), TemperatureDocument.NullDateString)]
        public DateTime ValueDate
        {
            get
            {
                return _ValueDate.Date ; 
            }
            set
            {
                _ValueDate = value.Date ; 
            }
        }

        private int _ValueTime = 0;
        /// <summary>
        /// 测量时刻，从0到23
        /// </summary>
        [DefaultValue( 0 )]
        public int ValueTime
        {
            get
            {
                return _ValueTime; 
            }
            set
            {
                _ValueTime = value % 24 ;
                if (_ValueTime < 0)
                {
                    _ValueTime = _ValueTime + 24;
                }
                
            }
        }

        private string _Memo = null;
        /// <summary>
        /// 标记文本
        /// </summary>
        [DefaultValue( null )]
        public string Memo
        {
            get { return _Memo; }
            set { _Memo = value; }
        }

        private float _Body_Temperature = TemperatureDocument.NullValue;
        /// <summary>
        /// 体温
        /// </summary>
        [DefaultValue( TemperatureDocument.NullValue )]
        public float Body_Temperature
        {
            get { return _Body_Temperature; }
            set { _Body_Temperature = value; }
        }

        private float _FT = TemperatureDocument.NullValue;
        [DefaultValue( TemperatureDocument.NullValue )]
        public float FT
        {
            get { return _FT; }
            set { _FT = value; }
        }

        private float _Pluse = TemperatureDocument.NullValue;
        /// <summary>
        /// 脉搏
        /// </summary>
        [DefaultValue ( TemperatureDocument.NullValue )]
        public float Pluse
        {
            get { return _Pluse; }
            set { _Pluse = value; }
        }

        private float _Breath = TemperatureDocument.NullValue;
        /// <summary>
        /// 呼吸
        /// </summary>
        [DefaultValue( TemperatureDocument.NullValue )]
        public float Breath
        {
            get { return _Breath; }
            set { _Breath = value; }
        }

        private DataRowState _RecordState = DataRowState.Unchanged;
        /// <summary>
        /// 记录状态
        /// </summary>
        [Browsable(false)]
        [System.Xml.Serialization.XmlIgnore]
        public DataRowState RecordState
        {
            get { return _RecordState; }
            set { _RecordState = value; }
        }

        /// <summary>
        /// 设置默认值
        /// </summary>
        public void SetDefaultValue()
        {
            this._Body_Temperature = 37.5f;
            this._Breath = 22;
            this._FT = 37.5f;
            this._Pluse = 80;
        }

        /// <summary>
        /// 复制对象
        /// </summary>
        /// <returns>复制品</returns>
        public Measure Clone()
        {
            return (Measure)this.MemberwiseClone();
        }

    }

    /// <summary>
    /// 数据记录列表
    /// </summary>
    /// <remarks>编制 袁永福</remarks>
    [ComVisible(false)]
    public class MeasureList : List<Measure>
    {
        /// <summary>
        /// 初始化对象
        /// </summary>
        public MeasureList()
        {
        }
        /// <summary>
        /// 深度复制
        /// </summary>
        /// <returns>复制品</returns>
        public MeasureList CloneDeeply()
        {
            MeasureList list = new MeasureList();
            foreach (Measure m in this)
            {
                list.Add(m.Clone());
            }
            return list;
        }
    }

    internal class MeasureComparer : IComparer<Measure>
    {
        public int Compare(Measure x, Measure y)
        {
            int result = DateTime.Compare(x.ValueDate, y.ValueDate);
            if (result == 0)
            {
                result = x.ValueTime - y.ValueTime;
            }
            return result;
        }
    }
}
